package com.nchu.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * Date:2023-07-11 10:08
 * Author：whx
 */
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    @Resource
    private LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册自己的拦截器,并设置拦截的请求路径
        //addPathPatterns为拦截此请求路径的请求
        //excludePathPatterns为不拦截此路径的请求
//        registry.addInterceptor(loginInterceptor).addPathPatterns("/**")//拦截所有请求，包括静态资源文件
//                .excludePathPatterns("/", "/login", "/login.html", "/css/**", "/images/**", "/js/**", "/fonts/**","favicon.ico");//放行登录页，登陆操作，静态资
    }

    //在配置类 MyMvcConfig 中添加视图映射
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //当访问 “/homepage.html” 时，直接跳转到登陆页面
        registry.addViewController("/").setViewName("login");
    }
}
